<template>
  <el-header>
    <div>
      <el-menu  default-active="index" active-text-color="#3D9AFB" class="el-menu-demo" mode="horizontal" :router="true" @select="handleSelect">
        <el-menu-item index="index">首页</el-menu-item>
        <el-menu-item index="classify">分类</el-menu-item>
        <el-menu-item v-show="isLogin" index="cart">购物车</el-menu-item>
        <el-menu-item  v-show="!isLogin" style="float: right" index="ulogin">登录</el-menu-item>
        <el-button  @click="logout" v-show="isLogin" style="float: right;margin-top: 10px">退出</el-button>
        <el-menu-item  v-show="isLogin" style="float: right" index="info">个人中心</el-menu-item>
        <el-menu-item  v-show="isLogin" style="float: right" index="userOrder">预约单</el-menu-item>
      </el-menu>
    </div>
  </el-header>
</template>

<script>
export default {
  name: "TopHeard",
  data(){
    return{
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',

      },
      formLabelWidth: '100px',
      dialogFormVisible:false,
      activeIndex:'1',
      isLogin:false
    }

  },
  mounted() {
  this.loginState();
    },
  methods:{
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    loginState(){
      const token=this.$store.getters.get_token;
      console.log(token)
      if (token!==null){
        this.isLogin=true
      }
      // this.isLogin=true
    },
    logout(){
      console.log('退出');
      const token=this.$store.getters.get_token;
      console.log(token)
      this.$axios.delete('/api/login/logout/' +token).then((res) => {
        this.$store.commit("del_token", {});
        this.$store.commit("del_userInfo", {});
        this.isLogin=false
        console.log(res)
        window.location.reload();
      });
    }

  }
}
</script>

<style scoped lang="less">
.el-header{
  height: 60px;
  background-color: #fff;
//border-bottom: 1px solid #dcdfe6;
  position: fixed;
  left:102px ;top : 0;right: 102px;
  z-index: 10000;
//display: flex;
}
</style>